/*****************************************************************************************
 * FILE NAME: srv_can                                 COPYRIGHT (c) TX 2024
 * REVISION:  1.0.0                                     All Rights Reserved
 * DESCRIPTION:
 * =======================================================================================
 * UPDATE HISTORY：
 * REV      AUTHOR      DATE
 * v1.0.0   Tuxin       2024.11.23
 * DESCRIPTION OF CHANGE:
 ****************************************************************************************/
#ifndef __SRV_CAN_H
#define __SRV_CAN_H

//----------------------------------------------------------------------------------------
// @Project Includes
#include "typedefs.h"

//----------------------------------------------------------------------------------------
// @Global Macro Define in the module
/* Acceptance filter. */
/***************卡奥斯升级协议相关开始**********/
#define CAN_UPG_INDEX_ID          (0x1871D4E0UL)
#define CAN_UPG_INDEX_ID_IDE      (CAN_ID_EXT)/*!< Accept frames with extended ID 0x1A1B1C1x, standard ID 0x41x(0x1A1B1C1D & 0x7FF(standard ID mask)). */
#define CAN_UPG_DATA_ID          	(0x1872D4E0UL)
#define CAN_UPG_DATA_ID_IDE      	(CAN_ID_EXT)
#define CAN_UPG_RESULT_ID         (0x1873D4E0UL)
#define CAN_UPG_RESULT_ID_IDE     (CAN_ID_EXT)

#define CAN_READ_ID         			(0x1876D4E0UL)/*PC 读寄存器*/
#define CAN_READ_ID_IDE     			(CAN_ID_EXT)
#define CAN_WRITE_ID         			(0x1877D4E0UL)/*PC 写寄存器*/
#define CAN_WRITE_ID_IDE     			(CAN_ID_EXT)

/* Message ID definitions. */
#define CAN_UPG_RESPOND_ID        (0x1874E0D4UL)
#define CAN_UPG_RESPOND_ID_IDE    (CAN_ID_EXT)/*扩展帧*/

#define CAN_READ_ACK_ID         	(0x1875E0D4UL)/*BMS 设置*/
#define CAN_READ_ACK_ID_IDE     	(CAN_ID_EXT)
#define CAN_WRITE_ACK_ID         	(0x1878E0D4UL)/*BMS 应答*/
#define CAN_WRITE_ACK_ID_IDE     	(CAN_ID_EXT)

/***************卡奥斯升级协议相关结束**********/

/* Size of the TX data. */
#define CAN_TX_DLC          ((uint8_t)8)
#define CAN_TX_DATA_SIZE    (8U)
//----------------------------------------------------------------------------------------
// @Global Type defines in the module
typedef union un_can_upgindex
{ 
    uint8_t Data[8];
    struct
    {
				uint64_t u16ver						:16;/*固件版本信息*/
				uint64_t u32size					:32;/*固件大小信息*/
				uint64_t u16crc						:16;/*固件CRC校验值*/			
    }Bit;
}un_can_upgindex_t;

typedef union un_can_upgdata
{ 
    uint8_t Data[8];
    struct
    {
				uint64_t u8packNumber			:8;/*升级包序号*/
				uint64_t packContent			:56;/*升级包内容*/		
    }Bit;
}un_can_upgdata_t;

typedef union un_can_upgresult
{ 
    uint8_t Data[8];
    struct
    {
				uint64_t u8result					:8;/*升级结果*/
				uint64_t back1      			:56;/*备用*/		
    }Bit;
}un_can_upgresult_t;

typedef union un_can_upgrespond
{ 
    uint8_t Data[8];
    struct
    {
				uint64_t u8result					:8;/*升级结果*/
				uint64_t back1      			:56;/*备用*/		
    }Bit;
}un_can_upgrespond_t;


typedef struct stc_srvcan
{
	  /*卡奥斯私有协议开始*/
    un_can_upgindex_t unfirmwareInfo;
    un_can_upgdata_t unfirmwareData;	
    un_can_upgresult_t unfirmwareResult;	
	
	  un_can_upgrespond_t ungeneralResponse;
		/*卡奥斯私有协议结束*/

} stc_srvcan_t;

//----------------------------------------------------------------------------------------
// @Export global Variables declare in the module
extern stc_srvcan_t g_stcSrvCan;

//----------------------------------------------------------------------------------------
// @Export declaration of functions in the module
void srv_can_task(void);

#endif

// =======================================================================================
// End of file.
// =======================================================================================
